#include "Text.h"

Text::Text()
{
	canvas = NULL;
	d_id = 1;
}
Text::Text(string _text,int _x, int _y, DrawingCanvas *_canvas)
{
	canvas = _canvas;
	d_id = canvas->addDrawing(Drawing(_text,_x,_y,d_text));
}
Text::Text(string _text,int _x, int _y,Color c, DrawingCanvas *_canvas)
{
	canvas = _canvas;
	d_id = canvas->addDrawing(Drawing(_text,_x,_y,c,d_text));
}
Text::Text(string _text, int _x, int _y, Color c, Color bg, DrawingCanvas *_canvas)
{
	canvas = _canvas;
	d_id = canvas->addDrawing(Drawing(_text,_x,_y,c,bg,d_text));
}

void Text::setText(string _text)
{
	if(canvas != NULL)
		canvas->getDrawing(d_id).setText(_text);
}
void Text::setFont(OSL_FONT *_font)
{
	if(canvas != NULL)
		canvas->getDrawing(d_id).setFont(_font);
}
void Text::setFontSize(float fsize)
{
	if(canvas != NULL)
		canvas->getDrawing(d_id).setFontSize(fsize);
}
void Text::setOptions(unsigned short int foptions)
{
	if(canvas != NULL)
		canvas->getDrawing(d_id).setOptions(foptions);
}
void Text::setBgColor(Color bg)
{
	if(canvas != NULL)
		canvas->getDrawing(d_id).setBgColor(bg);
}
string Text::getText()
{
	if(canvas != NULL)
		return canvas->getDrawing(d_id).getText();
	return "";
}
OSL_FONT* Text::getFont()
{
	if(canvas != NULL)
		return canvas->getDrawing(d_id).getFont();
	return NULL;
}
float Text::getFontSize()
{
	if(canvas != NULL)
		return canvas->getDrawing(d_id).getFontSize();
	return 0;
}
unsigned short int Text::getOptions()
{
	if(canvas != NULL)
		return canvas->getDrawing(d_id).getOptions();
	return 0;
}
Color Text::getBgColor()
{
	if(canvas != NULL)
		return canvas->getDrawing(d_id).getBgColor();
	return Color(0,0,0);
}
int Text::getWidth()
{
	if(canvas != NULL)
		return oslGetStringWidth(canvas->getDrawing(d_id).getText().c_str());
	return 0;
}
int Text::getHeight()
{
	if(canvas != NULL)
		return canvas->getDrawing(d_id).getFont()->charHeight;
	return 0;
}
Size Text::getSize()
{
	if(canvas != NULL)
		return Size(getWidth(),getHeight());
	return Size(0);
}
